const app = getApp();
const regeneratorRuntime = global.regeneratorRuntime = require("../libs/regenerator");
const co = require('../libs/co');
const time = require('../libs/util');


Page({
  data:{
    hidden:false,
    order:{},
    actionMsg:"",
    createDate: ""
  },

  onReady() {

  },
  onLoad: function(options) {
      app.launchOptions = options;
      /* !Do not Remove the follow line, used for build tool.*/
      let orderNum = options.orderNum;
      this.loadOrder(orderNum);
  },
  loadOrder: function (orderNum) {
    const self = this;
    co(function *() {
        let orderService = require("../services/mall/orderService");
        let order = yield orderService.info(orderNum);
        let dateStr = time.formatTimeUtc(new Date(order.addTime * 1000));

        self.setData({
            hidden:true,
            order: order,
            createDate: dateStr
        });
    });
  },

  onShow:function(){
  },
  onTextAreaBlur: function (e){
    let value = e.detail.value;
     console.log(value);

     this.setData({
       actionMsg: value
     });
  },
  onTouchedOrder:function(e) {
    let orderNum = e.currentTarget.dataset.no;
    this.showModel(orderNum,"APPLY_REFUND");
  },
  showModel: function (orderNum,status){
    let msgText = "是否确认提交退款申请?";
    const self = this;
    wx.showModal({
          title: '提示',
          content: msgText,
          confirmText: "确定",
          cancelText: "取消",
          success: function (res) {
              if (res.confirm) {
                  self.doOrder(orderNum,status,self.data.actionMsg);
              }else{
              }
          }
      });
  },
  doOrder: function (orderNum,status,msg) {
    this.setData({
      hidden:false
    });
    const self = this;
    co(function *() {
        let orderService = require("../services/mall/orderService");
        let ret = yield orderService.doOrder(orderNum,status,msg);
        console.log(ret);
        self.setData({
          hidden:true
        });
        if (ret) {
          wx.navigateBack({});
        }
    });
  }
})
